package jianzhiOffer;

public class Num47 {
    public int maxValue(int[][] grid) {
        int rol = grid.length;
        int cow = grid[0].length;
        for(int i = 0; i < rol; i++) {
            for(int j = 0; j < cow; j++) {
                if(i - 1 >= 0 && j - 1 >= 0) {
                    grid[i][j] = Math.max(grid[i - 1][j],grid[i][j - 1]) + grid[i][j];
                }else if(i - 1 >= 0) {
                    grid[i][j] = grid[i - 1][j] + grid[i][j];
                }else if(j - 1 >= 0){
                    grid[i][j] = grid[i][j - 1] + grid[i][j];
                }
            }
        }
        return grid[rol - 1][cow - 1];
    }
}
